const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
console.log(CleanWebpackPlugin);


console.log(process.env.NODE_ENV);
module.exports = {
    //...
    mode: 'development',
    entry: {
        test: './src/js/test.js',
    },
    output: {
        filename: '[name].js',
        chunkFilename: (pathData) => {
            return pathData.chunk.name === 'main' ? '[name].js' : '[name]/[name].js';
        },

    },
    module: {
        rules: [
            { test: /\.css/, use: ['style-loader', 'css-loader', ] },
            //打包背景图片
            {
                test: /\.(png|jpg|jiff|webp)$/i,
                loader: 'url-loader',
                options: {
                    name: '[hash].[ext]',
                    limit: 10* 1024,
                    esModule: false,
                },
                type: 'javascript/auto'
             },
             //打包less
             {  test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
             //打包html
             { test: /\.html$/, use: ['html-loader'] }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html',
        }),
        new CleanWebpackPlugin()
    ]


};